home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / igo / src / gadget.c < prev    next >
C/C++ Source or Header  |  1993-07-08  |  6KB  |  301 lines

  1. #define    DEBUG    0
  2. /* 
  3.     TOWNS囲碁棋譜記録プログラム gadget.c
  4.                                           1992/05/05  久保田俊也
  5.  
  6. */
  7. #include <stdio.h>
  8. #include <time.h>
  9. #include "igo.h"
  10. #include "ban19.h"
  11. #define MAX_ABLE_NUMBER 400 /* 打つことができる盤の最大位置 */
  12. int uchiage(int ichi, char ban[])
  13. {
  14. int i, j;
  15. int k = 0;
  16. char g_no[MAX_ABLE_NUMBER];
  17.  
  18.     for(i=0;i<MAX_ABLE_NUMBER;i++){
  19.         g_no[i] = 0;
  20.     }
  21.  
  22.     for(i=21;i<MAX_ABLE_NUMBER;i++){
  23.         if(ban[i] == BLACK || ban[i] == WHITE){
  24.         if(ban[i] == ban[i+UP]){
  25.             g_no[i] = g_no[i+UP];
  26.             if(ban[i] == ban[i+LEFT]){
  27.                 for(j=22;j<i;j++){
  28.                     if(g_no[j] == g_no[i+LEFT]){
  29.                         g_no[j] = g_no[i];
  30.                     }
  31.                 }
  32.             }
  33.  
  34.         }else{
  35.             if(ban[i] == ban[i+LEFT]){
  36.                 g_no[i] = g_no[i+LEFT];
  37.             }else{
  38.                 g_no[i] = ++k;
  39.             }
  40.         }
  41.         }
  42.     }
  43.  
  44.  
  45.     if(ban[ichi] != ban[ichi+UP] && ban[ichi+UP] !=WALL
  46.                      && ban[ichi+UP] !=BLANK ){
  47.         if(damesu(ichi+UP, g_no, ban) == 0){
  48.             for(i=21;i<MAX_ABLE_NUMBER;i++){
  49.                 if(g_no[i] == g_no[ichi+UP]){
  50.                     ban[i] = BLANK;
  51.                 }
  52.             }
  53.         }
  54.     }
  55.  
  56.     if(ban[ichi] != ban[ichi+LEFT] && ban[ichi+LEFT] !=WALL
  57.                      && ban[ichi+LEFT] !=BLANK ){
  58.         if(damesu(ichi+LEFT, g_no, ban) == 0){
  59.             for(i=21;i<MAX_ABLE_NUMBER;i++){
  60.                 if(g_no[i] == g_no[ichi+LEFT]){
  61.                     ban[i] = BLANK;
  62.                 }
  63.             }
  64.         }
  65.     }
  66.  
  67.     if(ban[ichi] != ban[ichi+RIGHT] && ban[ichi+RIGHT] !=WALL
  68.                      && ban[ichi+RIGHT] !=BLANK ){
  69.         if(damesu(ichi+RIGHT, g_no, ban) == 0){
  70.             for(i=21;i<MAX_ABLE_NUMBER;i++){
  71.                 if(g_no[i] == g_no[ichi+RIGHT]){
  72.                     ban[i] = BLANK;
  73.                 }
  74.             }
  75.         }
  76.     }
  77.  
  78.     if(ban[ichi] != ban[ichi+DOWN] && ban[ichi+DOWN] !=WALL
  79.                      && ban[ichi+DOWN] !=BLANK ){
  80.         if(damesu(ichi+DOWN, g_no, ban) == 0){
  81.             for(i=21;i<MAX_ABLE_NUMBER;i++){
  82.                 if(g_no[i] == g_no[ichi+DOWN]){
  83.                     ban[i] = BLANK;
  84.                 }
  85.             }
  86.         }
  87.     }
  88.     
  89.     return 0;
  90. }
  91.  
  92. damesu(ichi, g_no, ban) /* 現在は0とそれ以外しか区別していない */
  93. int ichi;
  94. char g_no[];
  95. char ban[];
  96. {
  97. int i;
  98.  
  99.     for(i=21;i<MAX_ABLE_NUMBER;i++){
  100.         if(g_no[i] == g_no[ichi]){
  101.             if(ban[i+UP]    == BLANK || ban[i+LEFT] == BLANK
  102.             || ban[i+RIGHT] == BLANK || ban[i+DOWN] == BLANK ){
  103.                 return(1);
  104.             }
  105.         }
  106.     }
  107.     
  108.     return(0);
  109.  
  110. }
  111.  
  112. int ban_init(size, ban)
  113. int size;
  114. char ban[];
  115. {
  116.     int i, j;
  117.  
  118.     for(i=0;i< (size+1)*(size+2)+1;i++){
  119.         ban[i] = WALL;
  120.     }
  121.     for(i=1;i<20;i++){
  122.         for(j=1;j<20;j++){
  123.             ban[j + i*20] = BLANK;    
  124.         }
  125.     }
  126.     return 0;
  127. }
  128.  
  129. handy_dispset(handy, ban)
  130. int    handy;
  131. char ban[BANSIZE2];
  132. {
  133.  
  134.     switch(handy){
  135.         case '2' + 0:
  136.             ban[96] = BLACK;
  137.             ban[324] = BLACK;
  138.             break;
  139.         
  140.         case '2' + 1:
  141.             ban[96] = BLACK;
  142.             ban[324] = BLACK;
  143.             ban[336] = BLACK;
  144.             break;
  145.         
  146.         case '2' + 2:
  147.             ban[84] = BLACK;
  148.             ban[96] = BLACK;
  149.             ban[324] = BLACK;
  150.             ban[336] = BLACK;
  151.             break;
  152.         
  153.         case '2' + 3:
  154.             ban[84] = BLACK;
  155.             ban[96] = BLACK;
  156.             ban[210] = BLACK;
  157.             ban[324] = BLACK;
  158.             ban[336] = BLACK;
  159.             break;
  160.         
  161.         case '2' + 4:
  162.             ban[84] = BLACK;
  163.             ban[96] = BLACK;
  164.             ban[204] = BLACK;
  165.             ban[216] = BLACK;
  166.             ban[324] = BLACK;
  167.             ban[336] = BLACK;
  168.             break;
  169.  
  170.         case '2' + 5:
  171.             ban[84] = BLACK;
  172.             ban[96] = BLACK;
  173.             ban[204] = BLACK;
  174.             ban[210] = BLACK;
  175.             ban[216] = BLACK;
  176.             ban[324] = BLACK;
  177.             ban[336] = BLACK;
  178.             break;
  179.             
  180.         case '2' + 6:
  181.             ban[84] = BLACK;
  182.             ban[90] = BLACK;
  183.             ban[96] = BLACK;
  184.             ban[204] = BLACK;
  185.             ban[216] = BLACK;
  186.             ban[324] = BLACK;
  187.             ban[330] = BLACK;
  188.             ban[336] = BLACK;
  189.             break;
  190.  
  191.         case '2' + 7:
  192.             ban[84] = BLACK;
  193.             ban[90] = BLACK;
  194.             ban[96] = BLACK;
  195.             ban[204] = BLACK;
  196.             ban[210] = BLACK;
  197.             ban[216] = BLACK;
  198.             ban[324] = BLACK;
  199.             ban[330] = BLACK;
  200.             ban[336] = BLACK;
  201.             break;
  202.  
  203.         case '2' + 8:
  204.             ban[84] = BLACK;
  205.             ban[96] = BLACK;
  206.             ban[324] = BLACK;
  207.             break;
  208.  
  209.         default:
  210.             break;
  211.     }
  212.     return 0;
  213. }
  214.  
  215. handy_prinset(handy, ban)
  216. int    handy;
  217. int ban[BANSIZE2];
  218. {
  219.  
  220.     switch(handy){
  221.         case '2' + 0:
  222.             ban[96] = HANDY_STONE;
  223.             ban[324] = HANDY_STONE;
  224.             break;
  225.         
  226.         case '2' + 1:
  227.             ban[96] = HANDY_STONE;
  228.             ban[324] = HANDY_STONE;
  229.             ban[336] = HANDY_STONE;
  230.             break;
  231.         
  232.         case '2' + 2:
  233.             ban[84] = HANDY_STONE;
  234.             ban[96] = HANDY_STONE;
  235.             ban[324] = HANDY_STONE;
  236.             ban[336] = HANDY_STONE;
  237.             break;
  238.         
  239.         case '2' + 3:
  240.             ban[84] = HANDY_STONE;
  241.             ban[96] = HANDY_STONE;
  242.             ban[210] = HANDY_STONE;
  243.             ban[324] = HANDY_STONE;
  244.             ban[336] = HANDY_STONE;
  245.             break;
  246.         
  247.         case '2' + 4:
  248.             ban[84] = HANDY_STONE;
  249.             ban[96] = HANDY_STONE;
  250.             ban[204] = HANDY_STONE;
  251.             ban[216] = HANDY_STONE;
  252.             ban[324] = HANDY_STONE;
  253.             ban[336] = HANDY_STONE;
  254.             break;
  255.  
  256.         case '2' + 5:
  257.             ban[84] = HANDY_STONE;
  258.             ban[96] = HANDY_STONE;
  259.             ban[204] = HANDY_STONE;
  260.             ban[210] = HANDY_STONE;
  261.             ban[216] = HANDY_STONE;
  262.             ban[324] = HANDY_STONE;
  263.             ban[336] = HANDY_STONE;
  264.             break;
  265.             
  266.         case '2' + 6:
  267.             ban[84] = HANDY_STONE;
  268.             ban[90] = HANDY_STONE;
  269.             ban[96] = HANDY_STONE;
  270.             ban[204] = HANDY_STONE;
  271.             ban[216] = HANDY_STONE;
  272.             ban[324] = HANDY_STONE;
  273.             ban[330] = HANDY_STONE;
  274.             ban[336] = HANDY_STONE;
  275.             break;
  276.  
  277.         case '2' + 7:
  278.             ban[84] = HANDY_STONE;
  279.             ban[90] = HANDY_STONE;
  280.             ban[96] = HANDY_STONE;
  281.             ban[204] = HANDY_STONE;
  282.             ban[210] = HANDY_STONE;
  283.             ban[216] = HANDY_STONE;
  284.             ban[324] = HANDY_STONE;
  285.             ban[330] = HANDY_STONE;
  286.             ban[336] = HANDY_STONE;
  287.             break;
  288.  
  289.         case '2' + 8:
  290.             ban[84] = HANDY_STONE;
  291.             ban[96] = HANDY_STONE;
  292.             ban[324] = HANDY_STONE;
  293.             break;
  294.  
  295.         default:
  296.             break;
  297.     }
  298.     return 0;
  299. }
  300.  
  301.